#include "loginbean.h"
#include "QJsonParseError"
#include "QJsonDocument"
#include "QJsonObject"

LoginBean::LoginBean()
{

}

void LoginBean::jsonToObject(QByteArray jsonArrayStr,LoginBean &loginBean)
{
    QJsonParseError jsonError;
    const QJsonDocument &document = QJsonDocument::fromJson(jsonArrayStr, &jsonError);
    if(document.isNull() || jsonError.error != QJsonParseError::NoError) return;
    if(!document.isObject()) return;
    QJsonObject obj = document.object();
    if(!obj.isEmpty()){
        if(obj.contains("message")){
            loginBean.message = obj.value("message").toString();
        }

        if(obj.contains("code")){

            loginBean.code = obj.value("code").toInt();
        }

        if(obj.contains("data")){
            QJsonObject dataObj = obj.value("data").toObject();
            if(dataObj.contains("token")){
                loginBean.data.token = dataObj.value("token").toString();
            }

            if(dataObj.contains("invalidTime")){
                loginBean.data.invalidTime = QString::number(dataObj.value("invalidTime").toDouble(), 'f', 0).toLongLong();
            }

            if(dataObj.contains("version")){
                loginBean.data.version = dataObj.value("version").toString().toInt();
            }

            if(dataObj.contains("url")){
                loginBean.data.url = dataObj.value("url").toString();
            }
        }
    }
}
